/*
 * @(#) ImageResizer.java 1.0  2011-7-22 
 *
 * (c) Copyright 2011 iflytek corejava
 *
 * FILENAME    : ImageResizer.java
 * PACKAGE     : wuyechun.myweb.test
 * CREATE DATE : 2011-7-22
 * AUTHOR      : Administrator
 */

package com.pur.zsms.common.util;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageResizer {

	/***
	 * 功能 :调整图片大小 开发：wuyechun 2011-7-22
	 * 
	 * @param srcImgPath
	 *            原图片路径
	 * @param distImgPath
	 *            转换大小后图片路径
	 * @param width
	 *            转换后图片宽度
	 * @param height
	 *            转换后图片高度
	 */
	public static void resizeImage(String srcImgPath, String distImgPath, int width, int height)
	        throws IOException {

		File srcFile = new File(srcImgPath);
		Image srcImg = ImageIO.read(srcFile);
		BufferedImage buffImg = null;
		buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		buffImg.getGraphics().drawImage(srcImg.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0,
		        null);

		ImageIO.write(buffImg, "JPEG", new File(distImgPath));

	}

}
